package com.ruoyi.flowable.config;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.flowable.ui.common.repository.UuidIdGenerator;
import org.flowable.ui.modeler.domain.ModelInformation;
import org.flowable.ui.modeler.domain.ModelRelation;
import org.flowable.ui.modeler.repository.ModelRelationRepository;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ModelRelationRepositoryImpl implements ModelRelationRepository {
    private static final String NAMESPACE = "org.flowable.ui.modeler.domain.ModelRelation.";
    @Autowired
    protected SqlSessionTemplate sqlSessionTemplate;
    @Autowired
    protected UuidIdGenerator idGenerator;

    public ModelRelationRepositoryImpl() {
    }

    public List<ModelRelation> findByParentModelIdAndType(String parentModelId, String type) {
        Map<String, Object> params = new HashMap();
        params.put("parentModelId", parentModelId);
        params.put("type", type);
        return this.sqlSessionTemplate.selectList("selectModelRelationByParentModelIdAndType", params);
    }

    public List<ModelInformation> findModelInformationByParentModelId(String parentModelId) {
        return this.sqlSessionTemplate.selectList("org.flowable.ui.modeler.domain.ModelRelation.selectModelInformationByParentModelId", parentModelId);
    }

    public List<ModelInformation> findModelInformationByChildModelId(String modelId) {
        return this.sqlSessionTemplate.selectList("org.flowable.ui.modeler.domain.ModelRelation.selectModelInformationModelId", modelId);
    }

    public void deleteModelRelationsForParentModel(String parentModelId) {
        this.sqlSessionTemplate.delete("org.flowable.ui.modeler.domain.ModelRelation.deleteModelRelationByParentModelId", parentModelId);
    }

    public void save(ModelRelation modelRelation) {
        if (modelRelation.getId() == null) {
            modelRelation.setId(this.idGenerator.generateId());
            this.sqlSessionTemplate.insert("org.flowable.ui.modeler.domain.ModelRelation.insertModelRelation", modelRelation);
        } else {
            this.sqlSessionTemplate.update("org.flowable.ui.modeler.domain.ModelRelation.updateModelRelation", modelRelation);
        }

    }

    public void delete(ModelRelation modelRelation) {
        this.sqlSessionTemplate.delete("org.flowable.ui.modeler.domain.ModelRelation.deleteModelRelation", modelRelation);
    }
}
